<?php
require_once 'Command.php';
require_once 'database/Product.php';
require_once 'database/DatabaseConnection.php';

class GetAllProductsCommand implements Command{
	
	private $product;
	
	public function __construct(){
		$this->product = new Product();
	}
	
	public function execute(){
		$string = "<products>";
		DatabaseConnection::connect();
		$arrayObj = $this->product->getAllProducts();
		DatabaseConnection::disconnect();
		$it = $arrayObj->getIterator();
		while($it->valid()){
			$arr = $it->current();
			$string .= "<product>";
			$string .= 	"<id>".$arr['id']."</id>";
			$string .= 	"<name>".$arr['name']."</name>";
			$string .= 	"<price>".$arr['price']."</price>";
			$string .= 	"<tag>".$arr['tag']."</tag>";
			$string .= "</product>";
			$it->next();
		}
		$string .= "</products>";
		return $string;
	}
}